package com.iweb.test;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.ws.spi.http.HttpContext;
import java.io.IOException;

/**
 * ClassName: UsernameFilter
 * Package: com.iweb.test
 * Description:
 *
 * @Author Jerry
 * @Create 2024/8/8 16:02
 * @Version 1.0
 */
@WebFilter(value="/success.html")
public class UsernameFilter extends HttpFilter {
    @Override
    protected void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain chain) throws IOException, ServletException {
        String username= req.getServletContext().getInitParameter("username");
        String user=req.getParameter("username");
        if(username.equals(user)){
            chain.doFilter(req,res);
        }else{
res.sendRedirect(req.getContextPath()+"/login.html?u=0");
        }
    }
}
